﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Groups;
using VK.Comm;
using VK.Casemeet.Merchants;

namespace VK.Casemeet.Web.ShopAdmin.Groups
{
    public partial class groupadd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/ShopAdmin/Home.aspx"},
                new MapPath{ Text="团购列表",Url="grouplist.aspx"},
                new MapPath{ Text="发布新团购",Url="#"}
            };

            if (!IsPostBack)
            {
                txtprocType.DataSource = GroupsBLL.GetCategories(0, "");
                txtprocType.DataValueField = "gc_id";
                txtprocType.DataTextField = "gc_name";
                txtprocType.DataBind();
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            var group = SetEntityGroup();
            if (GroupsBLL.AddGroups(group) > 0)
            {
                Message.Msg(this.Page, CS.MsgAddSuccess, MessageType.Success);
                Util.ClearControl((this.Master as Site).contentBody.Controls);


            }
            else
            {
                Message.Msg(this.Page, CS.MsgAddFailure, MessageType.Failure);
            }
        }

        private GroupsEntity SetEntityGroup()
        {
            GroupsEntity group = new GroupsEntity();
            group.ShopID = AdminBLL.GetSessionAdmin().ShopID;
            group.Title = txtTitle.Text;
            group.Price = decimal.Parse(txtPrice.Text);
            group.Discount = float.Parse(txtDiscount.Text);
            group.Foucsmap = VK.Comm.Util.GetFormString("hidFouceImgUrl");
            group.EndingTime = DateTime.Parse(VK.Comm.Util.GetFormString("txtTimes"));
            group.CTime = DateTime.Now;
            group.Content = txtContent.Value;
            group.isEnable = chkIsEnable.Checked;
            group.ProcTypeID = int.Parse(txtprocType.SelectedValue);
            return group;
        }
    }
}